<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseMenu {

	protected $m_intMid;
	protected $m_strTitle;
	protected $m_strPath;
	protected $m_strImgPath;
	protected $m_strParent;
	protected $m_intRank;
	protected $m_strDummy;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getMid(){
		return $this->m_intMid;
	}

	public function getTitle(){
		return $this->m_strTitle;
	}

	public function getPath(){
		return $this->m_strPath;
	}

	public function getImgPath(){
		return $this->m_strImgPath;
	}

	public function getParent(){
		return $this->m_strParent;
	}

	public function getRank(){
		return $this->m_intRank;
	}

	public function getDummy(){
		return $this->m_strDummy;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setMid( $Mid ){
		$this->m_intMid = $Mid;
	}

	public function setTitle( $Title ){
		$this->m_strTitle = $Title;
	}

	public function setPath( $Path ){
		$this->m_strPath = $Path;
	}

	public function setImgPath( $ImgPath ){
		$this->m_strImgPath = $ImgPath;
	}

	public function setParent( $Parent ){
		$this->m_strParent = $Parent;
	}

	public function setRank( $Rank ){
		$this->m_intRank = $Rank;
	}

	public function setDummy( $Dummy ){
		$this->m_strDummy = $Dummy;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into MENU (mid, title, path, img_path, parent, rank, dummy) values (" . $this->getMid() . ", '" . $this->getTitle() . "', '" . $this->getPath() . "', '" . $this->getImgPath() . "', '" . $this->getParent() . "', " . $this->getRank() . ", '" . $this->getDummy() . "')");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE MENU set  title= '" . $this->getTitle() . "', path= '" . $this->getPath() . "', img_path= '" . $this->getImgPath() . "', parent= '" . $this->getParent() . "', rank= " . $this->getRank() . ", dummy= '" . $this->getDummy() . "' where mid =" . $this->getMid() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM menu WHERE mid = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'menu'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}